import {
  Controller,
  Get,
  Post,
  Body,
  Param,
  Delete,
  Put,
} from '@nestjs/common';
import { EnumerateService } from './enumerate.service';
import { CreateEnumerateDto } from './dto/create-enumerate.dto'; // 导入DTO类
import { UpdateEnumerateDto } from './dto/update-enumerate.dto';
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';

@ApiTags('枚举管理')
@Controller('enumerate')
export class EnumerateController {
  constructor(private readonly enumerateService: EnumerateService) {}

  @Post()
  @ApiOperation({ summary: '创建枚举' })
  @ApiResponse({ status: 201, description: '创建成功' })
  create(@Body() createEnumerateDto: CreateEnumerateDto) {
    return this.enumerateService.createEnum(createEnumerateDto);
  }

  @Get()
  @ApiOperation({ summary: '获取所有枚举' })
  @ApiResponse({ status: 200, description: '获取成功' })
  async findAll() {
    return await this.enumerateService.getAllEnums();
  }

  // 一键导入数据
  @Post('import')
  @ApiOperation({ summary: '一键导入枚举数据' })
  @ApiResponse({ status: 200, description: '数据导入成功' })
  async importEnumData() {
    return await this.enumerateService.importEnumData();
  }

  @Get(':id')
  @ApiOperation({ summary: '根据ID获取单个枚举' })
  @ApiResponse({ status: 200, description: '获取成功' })
  async findOne(@Param('id') id: number) {
    return await this.enumerateService.getEnumById(id);
  }

  @Put(':id')
  @ApiOperation({ summary: '更新枚举' })
  @ApiResponse({ status: 200, description: '更新成功' })
  async update(
    @Param('id') id: number,
    @Body() updateEnumerateDto: UpdateEnumerateDto,
  ) {
    return await this.enumerateService.updateEnum(id, updateEnumerateDto);
  }

  @Delete(':id')
  @ApiOperation({ summary: '删除枚举' })
  @ApiResponse({ status: 204, description: '删除成功' })
  async remove(@Param('id') id: number) {
    return await this.enumerateService.deleteEnum(id);
  }

  @Post('bulk-create')
  @ApiOperation({ summary: '批量添加枚举' })
  @ApiResponse({ status: 201, description: '批量添加成功' })
  async bulkCreate(@Body() createEnumDtos: CreateEnumerateDto[]) {
    return await this.enumerateService.bulkCreateEnums(createEnumDtos);
  }

  @Post('bulk-delete')
  @ApiOperation({ summary: '批量删除枚举' })
  @ApiResponse({ status: 204, description: '批量删除成功' })
  async bulkDelete(@Body() ids: number[]) {
    return await this.enumerateService.bulkDeleteEnums(ids);
  }
}
